<?php

namespace app\admin\service;

use app\common\service\BaseService;

class AdminGroupService extends BaseService
{


    public function __construct()
    {
        parent::__construct();
        $this->model = new \app\admin\model\AdminGroup();
        $this->getTableName();
    }


    /**
     * 更新站点子账号权限
     * @param array $where
     * @param string $fatherRules
     * @return bool
     */
    public function updateChildRules(array $where, string $fatherRules)
    {
        $list = $this->model->where($where)->select();
        $ret = false;
        if(!empty($list)){
            $fatherRulesArr = explode(',',$fatherRules);
            foreach ($list as $item){
                $childRules = is_array($item->rules) ? $item->rules : explode(',',$item->rules);
                $rules = [];
                foreach ($childRules as $childRule){
                    if(in_array($childRule,$fatherRulesArr)){
                        $rules[] = $childRule;
                    }
                }
                $item->rules = implode(',',$rules);
                $ret = $item->save();
            }
        }
        return $ret;
    }




}